/*

 Copyright 2012 Peter Dornbach.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
   
*/

package com.dornbachs.zebra.guitarear;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends BaseActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
		findViewById(R.id.button_main_select_improve).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View view) {
						startActivity(new Intent(INTENT_SELECT_IMPROVE));
					}
				});
		findViewById(R.id.button_main_select_free).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View view) {
						startActivity(new Intent(INTENT_SELECT_PRACTICE));
					}
				});
		findViewById(R.id.button_main_about).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View view) {
						showDialog(DIALOG_ABOUT_ID);
					}
				});
    findViewById(R.id.button_main_exit).setOnClickListener(
    		new View.OnClickListener() {
    			public void onClick(View view) {
    				finish();
    			}
    		});
    
    // Make sure initialization happens here and not later.
    _challenge = Challenge.getChallenge(this);
    _challenge.setUserState(UserState.load(this));
  }
  
  @Override
  public void onPause() {
  	// Save instance state.
  	_challenge.getUserState().save(this);
  	super.onPause();
  }
  
	@Override
	protected Dialog onCreateDialog(int id) {
    AlertDialog dialog = null;
    switch(id) {
    case DIALOG_ABOUT_ID:
    	dialog = new AlertDialog.Builder(this).create();
			dialog.setMessage(getString(R.string.text_about));
    	dialog.setButton(
    			AlertDialog.BUTTON_POSITIVE,
    			getString(R.string.button_ok),
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              dialog.dismiss();
            }
          });
    	break;
    }
    return dialog;
  }
  
	private final static int DIALOG_ABOUT_ID = 1;
  
  private Challenge _challenge;
  
}